package com.excel.easyExcel.utils;

import com.alibaba.excel.context.AnalysisContext;
import com.alibaba.excel.event.AnalysisEventListener;
import com.alibaba.fastjson.JSON;
import lombok.extern.slf4j.Slf4j;

import java.util.ArrayList;
import java.util.List;

/**
 * @author Xinjie
 * @date 2023/4/27 13:46
 */
@Slf4j
public class ExcelReadListener<T> extends AnalysisEventListener<T> {
    List<T> data = new ArrayList<>();
    public ExcelReadListener(){

    }
    @Override
    public void invoke(T t, AnalysisContext analysisContext) {
        log.info("解析到的一条数据："+ JSON.toJSONString(t));
        data.add(t);
    }

    @Override
    public void doAfterAllAnalysed(AnalysisContext analysisContext) {
        log.info("解析完毕");
    }

    public List<T> getData(){
        return data;
    }
}
